var Touringcar = require("../../../class/user/touringcar.c");
module.exports = {
    prefix: "/user/touringcar/",
    get:{
    	'list':{
    		 des: {
    		 	name:'getTouringcarList',
    		 	content:'获取房车列表',
    		 	params:[
    		 		{
    		 			key:'page',
    		 			type:'int'
    		 		},
                    {
                        key:'module',
                        type:'string'
                    },
                    {
                        key:'price',
                        type:'float'
                    }
    		 	]
    		 },
    		 method: function* () {
            	var self = this;
            	try {
                    var data = yield new Touringcar(self.request.query).getlist();
                	self.body = data;
                } catch (e) {
                    self.body = printError(e);
                };
            }
    	},
        'listimage':{
            des: {
                name:'getTouringcarListimage',
                content:'获取房车列表图片',
                params:[]
             },
             method: function* () {
                var self = this;
                try {
                    var inser_data = {page:1}
                    var data = yield new Touringcar(inser_data).getlist();
                    var len = data.length;
                    len = len>4?4:len;
                    var image;
                    var arr_image = [];
                    var temp_arr_image = [];
                    for(var i=0;i<len;i++){
                        image = data[i].image;
                        if (typeof image == 'string') {
                            temp_arr_image = image.split(',');
                            arr_image[i] = {image:temp_arr_image[0]};
                        } else {
                            arr_image[i] = image;
                        }
                    }
                    self.body = arr_image;
                } catch (e) {
                    self.body = printError(e);
                };
            }
        },
        'count':{
            des: {
                name:'getTouringcarCount',
                content:'获取房车数量',
                params:[]
             },
             method:function* (){
                var self = this;
                try {
                    var count = yield new Touringcar().count();
                    self.body = count;
                } catch (e) {
                    self.body = printError(e);
                };
             }
        },
        'detail/:_id':{
            des:{
                name:'getTouringcarDetail',
                content:'获取房车详情',
                params:[{
                    key:'_id',
                    type:'string'
                }]
            },
            method:function* (){
                var self = this;
                try{
                    var data = yield new Touringcar().getDetail(self.params._id);
                    self.body = data;
                }catch(e){
                    self.body = pringErooro(e);
                };
             }
        }
    },
    post:{
        'addTouringcar':{
             des: {
                name:'addTouringcar',
                content:'用户购买房车',
                params:[
                    {
                        key:'car_id',
                        type:'string',
                        describe:'房车ID'
                    },
                    {
                        key:'buynumber',
                        type:'int',
                        describe:'房车租赁天数'
                    }
                ]
             },
             method: function* () {
                var self = this;
                try {
                    var data = yield new Touringcar(self.request.body,self.session.user).addTouringcar();
                    self.body = data;
                } catch (e) {
                    self.body = printError(e);
                };
            }
        },
    }
};
